package com.example.chess2;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	MyImageView myView;
	private boolean isExit = false;
	
    @SuppressLint("WrongCall") @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(new MyView(this));
        setContentView(R.layout.activity_main);

        Button button = (Button) findViewById(R.id.reBack);
        myView = (MyImageView) findViewById(R.id.myImageView);
        
        button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_SHORT).show();
				myView.reBack();
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present. 
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		   if (keyCode == KeyEvent.KEYCODE_BACK) {  
		        if(!isExit) {  
		            isExit = true;    
		            Toast.makeText(getApplicationContext(), R.string.RepeatBackKeyToExit, Toast.LENGTH_SHORT).show();  
		            new Handler().postDelayed(new Runnable(){  
		                public void run(){  
		                    isExit = false;  
		                }  
		            }, 2000);;  
		            return false;  
		        }  
		    }  
		  
		    return super.onKeyDown(keyCode, event);  
	}
    
    

}
